<template>
  <div >
    <i-vxe-table ref="iVxeTableRef" :tableData="tableData"></i-vxe-table>
        <lib-doc :libDocData="libDocData"></lib-doc>
  </div>
</template>

<script lang="ts">
import { defineComponent, reactive, ref } from 'vue'
import { IVxeTable } from 'wd-platform-library'
import {
    TableDataInterFace,
    PageInfoInterFace,
    ResultInterFace
} from 'wd-platform-library/lib/src/IVxeTable/src/IVxeTableInterFace'
import LibDoc from '@/components/LibDoc.vue'
import { LibDocInterface } from '@/service/LibDocService'
interface AppResult {
  appName: string;
  price:string;
  time:string;
}

export default defineComponent({
    name: 'i_from_demo',
    setup () {
        const iVxeTableRef = ref()
        const dataList = [
            {
                appName: '系统管理',
                price: '55',
                time: '1638933537'
            },
            {
                appName: '产品管理',
                price: '55',
                time: '1638933537'
            },
            {
                appName: '营销获客',
                price: '55',
                time: '1638933537'
            },
            {
                appName: '线上资源',
                price: '55',
                time: '1638933537'
            },
            {
                appName: '订单管理',
                price: '55',
                time: '1638933537'
            },
            {
                appName: '数据统计',
                time: '1638933537',
                price: '55'
            }
        ]
        const tableData = reactive<TableDataInterFace>({
            type: 'app_table', // 每个表格唯一表示符
            tableInfo: {
                columns: [
                    {
                        field: 'appName',
                        width: 150,
                        title: '应用名称',
                        fixed: 'left'
                    },
                    {
                        field: 'time',
                        minWidth: 200,
                        showOverflow: true,
                        format: 'time',
                        title: '时间'
                    },
                    {
                        field: 'price',
                        minWidth: 200,
                        showOverflow: true,
                        format: 'prick',
                        title: '金额'
                    },
                    {
                        field: 'time',
                        minWidth: 200,
                        format: 'date',
                        title: '日期'
                    }
                ], // 表头配置
                data: [] // 数据集合
            },
            callback: async (pageInfo: PageInfoInterFace) => {
                return {
                    resultList: dataList,
                    total: 10
                } as ResultInterFace<AppResult>
            }

        })
        const libDocData: LibDocInterface = {
            title: '自定义表格组件',
            docList: [
                {
                    label: '引入组件',
                    value: "import { IVxeTable } from 'wd-platform-library'"
                },
                {
                    label: '创建表格对象',
                    type: 'pre',
                    value: `
    const tableData = reactive<TableDataInterFace>({
            type: 'app_table', // 每个表格唯一表示符
            tableInfo: {
                columns: [
                    {
                        field: 'appName',
                        width: 150,
                        title: '应用名称',
                        fixed: 'left'
                    },
                    {
                        field: 'time',
                        minWidth: 200,
                        showOverflow: true,
                        format: 'time',
                        title: '时间'
                    },
                    {
                        field: 'price',
                        minWidth: 200,
                        showOverflow: true,
                        format: 'prick',
                        title: '金额'
                    },
                    {
                        field: 'time',
                        minWidth: 200,
                        format: 'date',
                        title: '日期'
                    }
                ], // 表头配置
                data: [] // 数据集合
            },
            callback: async (pageInfo: PageInfoInterFace) => {
                return {
                    resultList: dataList,
                    total: 10
                } as ResultInterFace<AppResult>
            },
            pageInfo: undefined

        })
        `
                },
                {
                    label: '关键代码',
                    type: 'pre',
                    value: `
    tableInfo:{
        columns: [
            {
                field: 'time',
                minWidth: 200,
                format:'time' //格式化表格内容 time:时间   prick:金额   date:日期
                title: '时间'
            }
        ]
    }`
                }
            ]
        }
        return {
            libDocData,
            tableData,
            iVxeTableRef
        }
    },
    components: {
        IVxeTable,
        LibDoc
    }
})
</script>

<style lang="scss" scoped>
.cus_template {
  display: flex;
}
</style>
